#!@GUILE@ --no-auto-compile
-*- scheme -*-
!#
;;; Joy -- implementation of the Joy programming language
;;; Copyright © 2016, 2017 Eric Bavier <bavier@member.fsf.org>
;;;
;;; Joy is free software; you can redistribute it and/or modify it under
;;; the terms of the GNU General Public License as published by the Free
;;; Software Foundation; either version 3 of the License, or (at your
;;; option) any later version.
;;;
;;; Joy is distributed in the hope that it will be useful, but WITHOUT
;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
;;; License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Joy.  If not, see <http://www.gnu.org/licenses/>.

(let ()
  (define-syntax-rule (push! elt v) (set! v (cons elt v)))

  (define (maybe-augment-load-paths!)
    (unless (getenv "JOY_UNINSTALLED")
            (push! "@joymoduledir@" %load-path)
            (push! "@guilemoduledir@" %load-path)
            (push! "@guileobjectdir@" %load-compiled-path)))

  (define (run-joy-main)
    (let ((joy-main (module-ref (resolve-interface '(joy ui))
				'joy-main)))
      (apply joy-main (program-arguments))))

  (maybe-augment-load-paths!)
  (exit (run-joy-main)))
